//Cracking the coding interview (5th), 1_6
//Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes,
//write a method to rotate the image by 90 degrees. Can you do this in place?
//Author: Fan Yang


#include<stdio.h>
#define SIZE 5

void Rotate90(int p[][SIZE])
{
	int t;
	for(int i=0;i<SIZE/2;i++)
		for(int j=i;j<SIZE-1-i;j++)
		{
			t=p[i][j];
			p[i][j]=p[SIZE-1-j][i];
			p[SIZE-1-j][i]=p[SIZE-1-i][SIZE-1-j];
			p[SIZE-1-i][SIZE-1-j]=p[j][SIZE-1-i];
			p[j][SIZE-1-i]=t;
    }
}

int main()
{
	int a[SIZE][SIZE]={{1,2,3,4,5},{1,2,3,4,5},{1,2,3,4,5},{1,2,3,4,5},{1,2,3,4,5}};
	Rotate90(a);
	for(int i=0;i<SIZE;i++)
	{
		for(int j=0;j<SIZE;j++)
		{
			printf("%d ",a[i][j]);
			if(j==SIZE-1)
				printf("\n");
		}
	}
	return 0;
}